package cn.tedu.tnt_sky.service.Impl;


import cn.tedu.tnt_sky.common.result.PageResult;
import cn.tedu.tnt_sky.mapper.admin.AdminMapper;
import cn.tedu.tnt_sky.mapper.admin.AdminUserMapper;
import cn.tedu.tnt_sky.pojo.dto.AdminUserPageDTO;
import cn.tedu.tnt_sky.pojo.dto.AdminUserUpdateDTO;
import cn.tedu.tnt_sky.pojo.vo.AdminUserVO;
import cn.tedu.tnt_sky.service.AdminUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class AdminUserServiceImpl implements AdminUserService {
    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private AdminUserMapper adminUserMapper;
    /**
     * 实现分页功能
     * @param adminPageDTO
     * @return
     */
    @Override
    public PageResult pageQuery(AdminUserPageDTO adminPageDTO) {
        PageHelper.startPage(adminPageDTO.getPage(),adminPageDTO.getPageSize());
        Page<AdminUserVO> page = adminMapper.pageQuery(adminPageDTO);
        log.info("page:{}",page);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 修改用户数据
     * @param adminUserUpdateDTO
     */
    @Override
    public void update(AdminUserUpdateDTO adminUserUpdateDTO) {
        adminUserUpdateDTO.setLoginTime(new Date());
        adminUserMapper.updateById(adminUserUpdateDTO);
    }

    /**
     * 根据ID删除用户
     * @param id
     */
    @Override
    public void delete(String id) {
        adminUserMapper.deleteById(id);
    }
}
